var queryParam = {"exampleType" : 2};
$(function(){
    getListPage();
});

function getListPage(param){
    param = $.extend(queryParam,param);
    $.ajax({
        type : "post",
        url : "htmlWeb/getExamplePageList",//,"payStatus" : -2
        data: param,
        async: false,
        success : function(data){
            $("#exampleVideoPageHead ~ tr").remove();
            var str = "";
            $.each(data.rows,function(i,obj){
                obj = trimEmpty(obj);
                var status = renderExampleStatus(obj.status);
                var comment = subStr(obj.descn);
                str += '<tr><td><p>' + obj.id + '</p></td>' +
                    '<td><span>' + obj.name + '</span></td>' +
                    '<td><p><img src="http://img.boyitongcheng.com/' + obj.imgUrl + '" width="80px" height="60px"></p></td>' +
                    '<td title="' + obj.descn + '"><span>' + comment + '</span></td>' +
                    '<td><span>' + status + '</span></td>' +
                    '<td><span class="userSpan"><a class="cur" href="javascript:void(0);" onclick="uploadVideo('+ obj.id + ')">编辑</a>';
                str += '<a class="cur" href="javascript:void(0);" onclick="uploadVideo('+ obj.id + ',-2)">删除</a>';
                if(obj.status == 1 || obj.status == 3){
                    str += '<a class="cur" href="javascript:void(0);" onclick="uploadVideo('+ obj.id + ',2)">上架</a>';
                }else if(obj.status == 1 || obj.status == 2 || obj.status == 5){
                    str += '<a class="cur" href="javascript:void(0);" onclick="uploadVideo('+ obj.id + ',3)">下架</a>';
                }else if(obj.status == 0){
                    str += '<a class="cur" href="javascript:void(0);" onclick="uploadVideo('+ obj.id + ',-1)">提交审核</a>';
                }
                str += '</span></td></tr>';
            });
            $("#exampleVideoPageHead").after(str);
            createPage(data);

        },
        error : function(data){
            console.log(data);
        }
    });
}

function uploadVideo(id,status) {
    if(status) {
        $.post("/htmlWeb/updateExampleView",{"id" : id,"status" : status},function(){
            tip("操作成功");
            goPage(1);

        });
    }else {
        var jsPath = "../../by-webhtml/assets/js/system/system_videoUpload.js";
        $(".mainDiv").load("/htmlWeb/systemVideoUploadHtml", '', function () {
            $("#videoId").val(id);
            $.getScript(jsPath);
        });
    }
}

